<?php

namespace App\Services\MongoDB;

use App\Models\MongoDB\MongoDBModel;
use App\Services\BaseServices;
use Illuminate\Support\Facades\DB;

class MongoDBServices extends BaseServices
{
    /**
     * 查询所有
     * @return array|null
     */
    public function findAllMo(): ?array
    {
        $data = MongoDBModel::all();
        if (is_null($data)) {
            return [];
        }
        return $data->toArray();
    }

    /**
     * 根据条件查询
     * @param  array  $where
     * @return array|null
     */
    public function findOneMo(array $where): ?array
    {
        $data = MongoDBModel::find($where);
        if (is_null($data)) {
            return [];
        }
        return $data->toArray();
    }

    /**
     * 添加
     * @param  array  $data
     * @return bool
     */
    public function insertMo(array $data): ?bool
    {
        $ret = MongoDBModel::insert($data);
        return $ret;
    }

    public function updateMo()
    {

    }

    /**
     * 删除
     * @param  array|null  $where
     * @return bool|null
     */
    public function deleteMo(array $where = null)
    {
        if (!is_null($where)) {
            $ret = MongoDBModel::where($where)->delete();
        } else {
            $ret = MongoDBModel::delete();
        }
        return $ret;
    }
}
